#!/bin/bash
#
# svn-create-project.bash
#
# 1. Create a directory structure to be imported into an SVN repository. The directory
# structure will be as follows -- for a project named, proj0:
#
#     /proj0/branches
#     /proj0/tags
#     /proj0/trunk
#
# 2. Import the project into repository: svn import proj0 file:///svn/proj0 -m "proj0 comment"
#

############################################################
# Help message
############################################################
function help() {
    echo "Usage: svn-create-project.sh <project_name> <svn_path>"
    echo "    svn_path: file path to svn repository"
}

echo "================================================================="
echo "Script: svn-create-project.bash (begin)"

if [ $(which svn > /dev/null 2>&1 ; echo $?) -ne 0 ];
then
    echo "Error: svn could not be found. Please make sure you executed yum-install.bash initially."
    exit 1
fi

if [ $# -ne 2 ]; 
then
    echo "Error: Invalid number of arguments"
    help
    exit 1
fi

PROJECT_NAME=$1
SVN_DIR=$2

if [ "$PROJECT_NAME" -eq "" ];
then
    echo "Error: $0 requires a project name"
    help
    exit 1
fi

if [ "$SVN_DIR" -eq "" ];
then
    echo "Error: $0 requires svn directory location"
    help
    exit 1
fi

mkdir -p $PROJECT_NAME
mkdir -p $PROJECT_NAME/branches
mkdir -p $PROJECT_NAME/tags
mkdir -p $PROJECT_NAME/trunk
echo "Created project directory for subversion."

echo "Importing to file://$SVN_DIR/$PROJECT_NAME"
svn import $PROJECT_NAME file://$SVN_DIR/$PROJECT_NAME -m "Initial import by svn-create-project.bash: $PROJECT_NAME"

rm -Rf $PROJECT_NAME
echo "Please check out the project at file://$SVN_DIR/$PROJECT_NAME"

echo "Script: end"
echo "================================================================="

